package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Login
 */
@WebServlet("/login")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Login() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		 String R_name = request.getParameter("username");
		    String R_password = request.getParameter("password");
		    PrintWriter out = response.getWriter();
		    
		users user = new users();
		if(R_name.equals(user.getUsername())&&R_password.equals(user.getPassword())){
			out.write("登陆成功");
		}
		else {
			out.write("登陆失败，请重新登陆");
			out.print("<!DOCTYPE html>\r\n" + 
					"<html>\r\n" + 
					"<head>\r\n" + 
					"<meta charset=\"UTF-8\">\r\n" + 
					"<title>Insert title here</title>\r\n" + 
					"</head>\r\n" + 
					"<body>\r\n" + 
					"\r\n" + 
					"<input type=\"button\" name=\"back\" value=\"返回\" onclick=\"goUrl()\">\r\n" + 
					"\r\n" + 
					"<script type=\"text/javascript\">\r\n" + 
					"    function goUrl() {\r\n" + 
					"        location.href = \"work2.html\";\r\n" + 
					"    }\r\n" + 
					"  </script>\r\n" + 
					"</body>\r\n" + 
					"</html>");
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
